//
//  WKProfireViewController.m
//  WeKeTang
//
//  Created by ichina on 2017/8/22.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import "WKProfireViewController.h"
#import "UIView+Extension.h"
#import "WKDiscountCouponModel.h"
#import "TencentClient.h"
#import "WKProfileCell.h"
#import "NSString+KZExtension.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
#import "WKFMDBTools.h"
#define kHeaderHeight 200
static NSString *const cellID = @"userCell";

@interface WKProfireViewController ()<UITableViewDelegate,UITableViewDataSource,WKShareViewDelegate>

@property (nonatomic, strong) UIButton *btnBack;

@property (nonatomic, strong) NSArray *images;

@property (nonatomic, strong) NSArray *titles;

@property (nonatomic, strong) NSArray *downLoadList;

@property (nonatomic, strong) NSArray *watchList;

@property (nonatomic, strong) YYLabel *noMemberLabel;

@property (nonatomic, strong) YYLabel *numLabel;

@property (nonatomic, strong) NSArray *dataList;

@property (nonatomic, strong) NSArray *expireList;

@property (nonatomic, strong) UITableView *mainTableView;

@property (nonatomic, copy) NSString *userVip;

@end

@implementation WKProfireViewController{
    UIView              *_headerView;
    UIImageView         *_headerImageView;
    UIView              *_lineView;
    UIStatusBarStyle    _statusBarStyle;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [self setupUI];
    
    [self loadData];
    
    [self loadAuditData];
    //下载数量
    [self loadDownloadData];
    //收藏数量
    [self loadCollectionData];
    //观看数量
    [self loadWatchData];
    //优惠券数量
    [self loadDiscountCouponData];
    
    [self loadMessageCount];
    self.statusbar.backgroundColor = [UIColor blackColor];
    self.navgationBar.backgroundColor = [UIColor clearColor];
   
    
    
}
- (void)backAction{
    
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    WKHomeViewController *homeVC = [[WKHomeViewController alloc]init];
    homeVC.userId = userid;
    WKNavgationController *navVC = [[WKNavgationController alloc]initWithRootViewController:homeVC];
    [UIApplication sharedApplication].keyWindow.rootViewController = navVC;
}
#pragma mark -获取收藏数量
- (void)loadCollectionData{
    
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSString *mac = [WKUniversal macaddress];
    NSString *phpsessid = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"collectinfo" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:mac forKey:@"mac"];
    [para setObject:phpsessid forKey:@"phpsessid"];
    
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:nil completionHandler:^(id responseObject) {
    } errorHandler:^(NSError *error) {
        NSLog(@"%@",error);
        [weakSelf showCustomAlertMessage:@"网络错误"];
    } finishHandler:^(id responseObject) {
        NSLog(@"网络错误：%@",responseObject);
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSDictionary *head = dict[@"head"];
        NSDictionary *body = dict[@"body"];
        NSArray *pack = body[@"pack"];
        NSArray *course = body[@"course"];
        NSString *statuscode = head[@"statuscode"];
        if ([statuscode intValue] == 100) {
            weakSelf.collectionNumLabel.text = [NSString stringWithFormat:@"%u",pack.count+course.count];
        }else{
            //[weakSelf showCustomAlertMessage:@"网络错误"];
        }
    }];
}
#pragma mark - 获取下载数据
- (void)loadDownloadData{
    
    self.downLoadList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusFinish].mutableCopy;
    self.downLoadNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.downLoadList.count];
}
#pragma mark - 获取观看数据
- (void)loadWatchData{
    
  self.watchList = [[WKFMDBTools defaultFMDBToos] QueryWatchDataWithKey:kDBWatchTableName].mutableCopy;
    self.watchNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.watchList.count];
    NSLog(@"观看数量:%ld",self.watchList.count);
}
#pragma mark - 获取消息数量
- (void)loadMessageCount{
    
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"noticenews" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:nil completionHandler:^(id responseObject) {
        
    } errorHandler:^(NSError *error) {
        
        //[weakSelf showCustomAlertMessage:@"网络错误"];
    } finishHandler:^(id responseObject) {
        
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSLog(@"个人中心：%@",dict);
        NSDictionary *head = dict[@"head"];
        NSString *body = dict[@"body"];
        NSString *statusCode = head[@"statuscode"];
        if ([statusCode intValue] == 100) {
        }
        if ([body intValue] == 1) {
            weakSelf.redLabel.hidden = NO;
            
        }else if ([body intValue] == 0){
            weakSelf.redLabel.hidden = YES;
        }
    }];
    
}
#pragma mark - 审核接口
- (void)loadAuditData{
    __weak typeof(self) weakSelf = self;
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    //先获取当前的版本号
    NSString *version =[NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    //再读区本地存储的版本好
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"featureswitch" forKey:@"commandid"];
    [para setObject:version forKey:@"version"];
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:@"" completionHandler:^(id responseObject) {
        
    } errorHandler:^(NSError *error) {
        
    } finishHandler:^(id responseObject) {
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSDictionary *head = dict[@"head"];
        NSString *statuscode = head[@"statuscode"];
        NSLog(@"审核接口:%@",dict);
        if ([statuscode intValue] == 100) {
            weakSelf.userVip = @"on";
        }else{
            weakSelf.userVip = @"off";
        }
        [weakSelf.mainTableView reloadData];
        
    }];
    
}
- (void)setUserVip:(NSString *)userVip{
    _userVip = userVip;

    [self.mainTableView reloadData];
}
#pragma mark - 优惠券数量
- (void)loadDiscountCouponData{
    
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSString *sessid = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    NSString *mac = [WKUniversal macaddress];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"wkcouponlist" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:mac forKey:@"mac"];
    [para setObject:sessid forKey:@"phpsessid"];
    [[WKNetworkTools shareManger] setHttpMethod:@"POST"];
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:@"获取中..." completionHandler:^(id responseObject) {
    } errorHandler:^(NSError *error) {
        
    } finishHandler:^(id responseObject) {
        NSDictionary *dict = [responseObject mj_JSONObject];
            NSLog(@"优惠券：%@",dict);
        NSDictionary *headDict = dict[@"head"];
        NSString *statuscode = headDict[@"statuscode"];
        NSArray *bodyList = dict[@"body"];
//        NSString * hostdateStr = [WKLoginHandel getLoginDataWithString:@"hostdate"];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
//        NSDate *hostdate = [dateFormatter dateFromString:hostdateStr];
        
        //        NSString *msg = headDict[@"message"];
        if ([statuscode intValue] == 100) {
            NSMutableArray *mArry = [NSMutableArray arrayWithCapacity:bodyList.count];
            NSMutableArray *expireArry = [NSMutableArray arrayWithCapacity:bodyList.count];
            for (NSInteger i = 0; i<bodyList.count; i++) {
                WKDiscountCouponModel *model = [WKDiscountCouponModel mj_objectWithKeyValues:bodyList[i]];
                if ([model.usestatus isEqualToString:@"0"]) {
                     [mArry addObject:model];
                    
                }
//                NSDate *expireDate = [dateFormatter dateFromString:model.expiretime];
                //比较时间
//                NSInteger index = [weakSelf compareOneDay:hostdate withAnotherDay:expireDate];
//                if (index == 1) {
//                    //过期
//                    [expireArry addObject:model];
//                }else{
//                    //没过期
//                    [mArry addObject:model];
//                }
            }
            weakSelf.dataList = mArry.mutableCopy;
            weakSelf.expireList = expireArry.mutableCopy;
            weakSelf.numLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)weakSelf.dataList.count];
            if (self.dataList.count == 0) {
                weakSelf.numLabel.hidden = YES;
            }else{
                weakSelf.numLabel.hidden = NO;
            }
        }else if([statuscode intValue] == 999){
          
            weakSelf.numLabel.hidden = YES;
        }
    }];
    
}
- (void)setupUI{
    self.images = @[@"icon_discountcoupon",@"icon_openmember",@"icon_weikeka",@"icon_Invitefriends",@"icon_share",@"icon_idea",@"icon_setting"];
    self.titles = @[@"优惠券",@"开通会员/续费",@"微课卡",@"邀请好友",@"分享",@"意见反馈",@"设置"];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:self.statusView];
    [self prepareTableView];
    [self prepareHeaderView];
    self.downLoadNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.downLoadList.count];
    self.watchNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.watchList.count];
}
#pragma mark - 获取个人信息
- (void)loadData{
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSLog(@"个人信息登录：%@",userid);
    NSString *SESSID = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    NSString *mac = [WKUniversal macaddress];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"personinfo" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:SESSID forKey:@"phpsessid"];
    [para setObject:mac forKey:@"mac"];
    
    NSString *hostdate = [WKLoginHandel getLoginDataWithString:@"hostdate"];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    dateFormatter.dateFormat=@"YYYY-MM-dd";
    NSDate * hostDate = [dateFormatter dateFromString:hostdate];
    NSLog(@"获取个人信息时间：%@",hostDate);
//    NSLog(@"获取个人信息参数：%@",para);
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    [[WKNetworkTools shareManger]RunRequest:para path:kServerDomain completionHandler:^(id responseObject) {
        
    } errorHandler:^(NSError *error) {
        [weakSelf showCustomAlertMessage:@"网络错误"];
    } finishHandler:^(id responseObject) {
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSDictionary *body =dict[@"body"];
        NSString *avatar = body[@"avatar"];
//        NSString *grade = body[@"grade"];
        NSString *nickname = body[@"nickname"];
        NSString *memberexptime = body[@"memberexptime"];
        NSLog(@"获取个人信息接口：%@",dict);
        
        NSData *data = [WKUniversal getImgData];
        UIImage *image = [UIImage imageWithData:data];
        if (data == nil) {
            [weakSelf.avaderImgView setImageWithURL:[NSURL URLWithString:avatar] options:YYWebImageOptionShowNetworkActivity];
        }else{
            weakSelf.avaderImgView.image = image;
        }
        if (nickname == nil || [nickname isEqualToString:@""]||nickname.length == 0) {
            weakSelf.nickLabel.text = body[@"mobile"];
        }else{
           weakSelf.nickLabel.text = nickname;
        }
        if (StringIsNullOrEmpty(memberexptime)) {
            weakSelf.juniorLabel.hidden = YES;
            weakSelf.highLabel.hidden = YES;
            weakSelf.juniorRemainingDayLabel.hidden = YES;
            weakSelf.hightRemainingDayLabel.hidden = YES;
            weakSelf.noMemberLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.avaderImgView.frame)+5, CGRectGetMaxY(self.nickLabel.frame)+5, 100, 21)];
            weakSelf.noMemberLabel.text = @"您还不是会员";
            weakSelf.noMemberLabel.textColor = [UIColor whiteColor];
            weakSelf.noMemberLabel.font = [UIFont systemFontOfSize:14];
            [_headerView addSubview:self.noMemberLabel];

        }
        if ([body[@"memberinfo"] isKindOfClass:[NSArray class]]) {
             NSArray * memberinfos = body[@"memberinfo"];
            if (memberinfos.count == 0) {
                weakSelf.juniorLabel.hidden = YES;
                weakSelf.highLabel.hidden = YES;
                weakSelf.juniorRemainingDayLabel.hidden = YES;
                weakSelf.hightRemainingDayLabel.hidden = YES;
            }
        }else if ([body[@"memberinfo"] isKindOfClass:[NSString class]]){
            
            if ([body[@"memberinfo"] isEqualToString:@"初中会员,高中会员"]) {
                
                weakSelf.juniorLabel.hidden = NO;
                weakSelf.highLabel.hidden = NO;
                weakSelf.juniorRemainingDayLabel.hidden = NO;
                weakSelf.hightRemainingDayLabel.hidden = NO;
                
                NSArray *memberexptimeArr = [memberexptime componentsSeparatedByString:@","];
                NSString *timeJur = memberexptimeArr.firstObject;
                NSString *timeHigh = memberexptimeArr.lastObject;
                NSString *yearJur = [timeJur substringWithRange:NSMakeRange(0, 4)];
                NSString *yearHigh = [timeHigh substringWithRange:NSMakeRange(0, 4)];
                 NSString *monthJur = [timeJur substringWithRange:NSMakeRange(4, 2)];
                NSString *monthHigh = [timeHigh substringWithRange:NSMakeRange(4, 2)];
                NSString *dayJur = [timeJur substringWithRange:NSMakeRange(6, 2)];
                NSString *dayHigh = [timeHigh substringWithRange:NSMakeRange(6, 2)];
                NSString *dateJur = [NSString stringWithFormat:@"%@-%@-%@",yearJur,monthJur,dayJur];
                NSString *dateHigh = [NSString stringWithFormat:@"%@-%@-%@",yearHigh,monthHigh,dayHigh];
                NSDate *jurDate = [self StringTODate:dateJur];
                NSDate *highDate = [self StringTODate:dateHigh];
                //计算两个中间差值(秒)
                NSTimeInterval jurtime = [hostDate timeIntervalSinceDate:jurDate];
                NSTimeInterval hightime = [hostDate timeIntervalSinceDate:highDate];
                NSInteger jurday = ((int)jurtime)/(3600*24);
                NSInteger hihtday = ((int)hightime)/(3600*24);
//                NSLog(@"nian剩余时间：%ld",ABS(jurday));
//                NSLog(@"nian剩余时间：%ld",ABS(hihtday));
                weakSelf.juniorRemainingDayLabel.text =[NSString stringWithFormat:@"剩余%ld天",ABS(jurday)];
                weakSelf.hightRemainingDayLabel.text = [NSString stringWithFormat:@"剩余%ld天",ABS(hihtday)];
            }else if ([body[@"memberinfo"] isEqualToString:@"初中会员"]){
                weakSelf.juniorLabel.hidden = NO;
                weakSelf.highLabel.hidden = YES;
                weakSelf.juniorRemainingDayLabel.hidden = NO;
                weakSelf.hightRemainingDayLabel.hidden = YES;
                NSString *yearJur = [memberexptime substringWithRange:NSMakeRange(0, 4)];
                NSString *monthJur = [memberexptime substringWithRange:NSMakeRange(4, 2)];
                NSString *dayJur = [memberexptime substringWithRange:NSMakeRange(6, 2)];
                NSString *dateJur = [NSString stringWithFormat:@"%@-%@-%@",yearJur,monthJur,dayJur];
                NSDate *jurDate = [self StringTODate:dateJur];
               NSTimeInterval jurtime = [hostDate timeIntervalSinceDate:jurDate];
                NSInteger jurday = ((int)jurtime)/(3600*24);
                weakSelf.juniorRemainingDayLabel.text =[NSString stringWithFormat:@"剩余%ld天",ABS(jurday)];
            }else if ([body[@"memberinfo"] isEqualToString:@"高中会员"]){
                weakSelf.juniorLabel.hidden = NO;
                weakSelf.highLabel.hidden = YES;
                weakSelf.juniorRemainingDayLabel.hidden = NO;
                weakSelf.hightRemainingDayLabel.hidden = YES;
                NSString *yearHigh = [memberexptime substringWithRange:NSMakeRange(0, 4)];
                NSString *monthHigh = [memberexptime substringWithRange:NSMakeRange(4, 2)];
                NSString *dayHigh = [memberexptime substringWithRange:NSMakeRange(6, 2)];
                NSString *dateHigh = [NSString stringWithFormat:@"%@-%@-%@",yearHigh,monthHigh,dayHigh];
                NSDate *highDate = [self StringTODate:dateHigh];
                NSTimeInterval hightime = [hostDate timeIntervalSinceDate:highDate];
                 NSInteger hihtday = ((int)hightime)/(3600*24);
                weakSelf.juniorRemainingDayLabel.text = [NSString stringWithFormat:@"剩余%ld天",ABS(hihtday)];
                weakSelf.juniorLabel.text = @"高中会员";
            }
        }
    }];
}

- (void)prepareHeaderView {

    _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kDeviceScreenWidth, kHeaderHeight)];
    _headerView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_headerView];
    _headerImageView = [[UIImageView alloc] initWithFrame:_headerView.bounds];
    _headerImageView.backgroundColor = RGBColor(88, 115, 175);
    // 设置 contentMode
    _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
    // 设置图像裁切
    _headerImageView.clipsToBounds = YES;
    [_headerView addSubview:_headerImageView];
    // 添加分隔线 一个像素点
    CGFloat lineHeight = 1 / [UIScreen mainScreen].scale;
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeaderHeight - lineHeight, _headerView.width, lineHeight)];
    _lineView.backgroundColor = [UIColor lightGrayColor];
    [_headerView addSubview:_lineView];
    // 设置图像
    _headerImageView.image =IMG(@"icon_profile_bg");
    [_headerView addSubview:self.btnBack];
    [_headerView addSubview:self.avaderImgView];
    [_headerView addSubview:self.nickLabel];
    [_headerView addSubview:self.juniorLabel];
    [_headerView addSubview:self.juniorRemainingDayLabel];
    [_headerView addSubview:self.highLabel];
    [_headerView addSubview:self.hightRemainingDayLabel];
    [_headerView addSubview:self.messageBtn];
    [_headerView addSubview:self.redLabel];
    [_headerView addSubview:self.collectionNumLabel];
    [_headerView addSubview:self.collectionLabel];
    [_headerView addSubview:self.leftLineView];
    [_headerView addSubview:self.downLoadNumLabel];
    [_headerView addSubview:self.downLoadLabel];
    [_headerView addSubview:self.rightLineView];
    [_headerView addSubview:self.watchNumLabel];
    [_headerView addSubview:self.watchLabel];
    
    
}
- (void)prepareTableView {
   
    self.mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, kDeviceScreenWidth, kDeviceScreenHeight-20) style:UITableViewStylePlain];
    self.mainTableView.dataSource = self;
    self.mainTableView.delegate = self;
    [self.mainTableView registerClass:[WKProfileCell class] forCellReuseIdentifier:cellID];
    [self.view addSubview:self.mainTableView];
    // 设置表格的间距
    self.mainTableView.contentInset = UIEdgeInsetsMake(kHeaderHeight, 0, 0, 0);
    // 设置滚动指示器的间距
    self.mainTableView.scrollIndicatorInsets = self.mainTableView.contentInset;
    self.mainTableView.tableFooterView = [[UIView alloc]init];
    self.mainTableView.backgroundColor = [UIColor whiteColor];
    self.mainTableView.separatorColor = [UIColor colorWithHexString:@"#f0f0f0"];
    self.mainTableView.separatorInset = UIEdgeInsetsMake(0,40, 0, 0);
//    self.mainTableView = tableView;
}
- (void)setDataList:(NSArray *)dataList{
    _dataList = dataList;
    self.numLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)dataList.count];
}
#pragma mark -数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.images.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WKProfileCell *cell = [[WKProfileCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    cell.separatorInset = UIEdgeInsetsMake(0, 40, 0, 0);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = UIColor.whiteColor;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.tag = indexPath.row;
    cell.title = self.titles[indexPath.row];
    cell.imgName = self.images[indexPath.row];
    if (indexPath.row == 0) {
        cell.imgView.hidden = YES;
        cell.titleLabel.hidden = YES;
        cell.accessoryType = UITableViewCellAccessoryNone;
        self.numLabel = [[YYLabel alloc]initWithFrame:CGRectMake(cell.width-60, (cell.height - 21)*0.5, 30, 21)];
        self.numLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.dataList.count];
        self.numLabel.textColor = [UIColor blackColor];
        self.numLabel.textAlignment = NSTextAlignmentRight;
        self.numLabel.hidden = YES;
        self.numLabel.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:self.numLabel];
    }
    if ([self.userVip isEqualToString:@"on"]) {
        if (indexPath.row == 2) {
            cell.imgView.hidden = YES;
            cell.titleLabel.hidden = YES;
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        
    }else if([self.userVip isEqualToString:@"off"]){
        if (indexPath.row == 2) {
            cell.imgView.hidden = NO;
            cell.titleLabel.hidden = NO;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }else{
        if (indexPath.row == 2) {
            cell.imgView.hidden = YES;
            cell.titleLabel.hidden = YES;
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
     if (indexPath.row == 3) {
     YYLabel *giftLabel = [[YYLabel alloc]initWithFrame:CGRectMake(cell.width-100, (50 - 21)*0.5, 80, 21)];
         
     giftLabel.text = @"会员无限送";
     giftLabel.textColor = RGBColor(79, 195, 208);
     giftLabel.textAlignment = NSTextAlignmentCenter;
     giftLabel.font = [UIFont systemFontOfSize:12];
     [cell.contentView addSubview:giftLabel];
     UIImageView *imgGift = [[UIImageView alloc]initWithFrame:CGRectMake(cell.width-100-10, (cell.height - 12)*0.5, 11, 12)];
         if (iPhone6sPlus) {
             giftLabel.frame = CGRectMake(cell.width-40, (50 - 21)*0.5, 80, 21);
             imgGift.frame = CGRectMake(cell.width-40-10, (cell.height - 12)*0.5, 11, 12);
         }
     imgGift.image = IMG(@"icon_present");
     [cell.contentView addSubview:imgGift];
     
     }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        return 0;
    }
    if ([self.userVip isEqualToString:@"on"]) {
        if (indexPath.row == 2) {
            return 0;
        }
    }else if ([self.userVip isEqualToString:@"off"]){
        if (indexPath.row == 2) {
            return 50;
        }
    }else{
        if (indexPath.row == 2) {
            return 0;
        }
    }
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.row) {
        case 0:
            [self performSelector:@selector(discountcouponAction) withObject:nil];
            break;
        case 1:
            [self performSelector:@selector(openMemberAction) withObject:nil];
            break;
        case 2:
            [self performSelector:@selector(weiKeKaAction) withObject:nil];
            break;
        case 3:
            [self performSelector:@selector(shareWebVCAction) withObject:nil];
            break;
        case 4:
            [self performSelector:@selector(shareAction) withObject:nil];
            break;
        case 5:
            [self performSelector:@selector(ideaAction) withObject:nil];
            break;
        case 6:
            [self performSelector:@selector(settingsAction) withObject:nil];
            break;
        default:
            break;
    }
    
}
#pragma mark - 个人信息
- (void)avaderAntion:(UITapGestureRecognizer*)tap{
    [MobClick profileSignInWithPUID:@"usercenter_avatar"];
     __weak typeof(self) weakSelf = self;
    WKPersonalInfoController *infoVC = [[WKPersonalInfoController alloc]init];
    infoVC.backBlock = ^{
        [weakSelf loadData];
    };
     [self.navigationController pushViewController:infoVC animated:YES];
}
#pragma mark - 消息
- (void)messageBtnAction:(UIButton*)sender{
    [MobClick profileSignInWithPUID:@"usercenter_message"];
    __weak typeof(self) weakSelf = self;
    
    WKMessageViewController *messageVC = [[WKMessageViewController alloc]init];
    messageVC.backBlock = ^{
      
        weakSelf.redLabel.hidden = YES;
        
    };
    [self.navigationController pushViewController:messageVC animated:YES];
}
#pragma mark -优惠券
- (void)discountcouponAction{
    [MobClick profileSignInWithPUID:@"usercenter_coupons"];
    
     WKDiscountCouponController *disVC = [[WKDiscountCouponController alloc]init];
    [self.navigationController pushViewController:disVC animated:YES];
    
}
#pragma mark -开通会员
- (void)openMemberAction{
    
    __weak typeof(self) weakSelf = self;
    [MobClick profileSignInWithPUID:@"usercenter_openmember"];
    WKMemberController *memberVC = [[WKMemberController alloc]init];
    memberVC.memberBlock = ^{
        [weakSelf loadData];
        [weakSelf loadDiscountCouponData];
    };
    [self.navigationController pushViewController:memberVC animated:YES];
}
#pragma mark -微课卡
- (void)weiKeKaAction{
    [MobClick profileSignInWithPUID:@"usercenter_weikecard"];
    __weak typeof(self) weakSelf = self;
    WKWeiKeKaController *wikekaVC = [[WKWeiKeKaController alloc]init];
    wikekaVC.weikekaBlock = ^{
        [weakSelf loadData];
    };  
    [self.navigationController pushViewController:wikekaVC animated:YES];
    
}
#pragma mark - 邀请好友
- (void)shareWebVCAction{
    WKWebViewController *shareWebVc = [[WKWebViewController alloc]init];
    shareWebVc.isShare = YES;
    shareWebVc.urlStr = [NSString stringWithFormat:@"%@/andriodwk/invite-index",kTestMainUrl];
    [self.navigationController pushViewController:shareWebVc animated:YES];
}
#pragma mark -分享
- (void)shareAction{
    [MobClick profileSignInWithPUID:@"usercenter_share"];
    
    [self.view addSubview:self.shareView];
}
#pragma mark - WKShareViewDelegate
- (void)WKShareView:(WKShareView *)shareView buttonIndex:(NSInteger)index{
    
    switch (index) {
        case 0:
            [self shareQQFriends];
            break;
        case 1:
            [self shareQQZone];
            break;
        case 2:
            [self shareWechatFriendsCircle];
            break;
        case 3:
            [self shareWechatFriends];
            break;
        
        default:
            break;
    }
    
    [shareView removeFromSuperview];
}
#pragma mark - QQ好友
- (void)shareQQFriends{
    
     [[TencentClient shareTencentClient] sendToQQ:@"http://www.dezhi.com/andriodwk/share-download" title:@"【德智微课堂】新用户下载即送会员大礼包" desctiption:@"我正在德智微课堂学习名师课程，领大礼包学8700个初高中必考知识点!" imageUrl:kLogoUrl];
   
}
#pragma mark - QQ空间
- (void)shareQQZone{
    
 [[TencentClient shareTencentClient] sendToQZone:@"http://www.dezhi.com/andriodwk/share-download" title:@"【德智微课堂】新用户下载即送会员大礼包" desctiption:@"我正在德智微课堂学习名师课程，领大礼包学8700个初高中必考知识点!" imageUrl:kLogoUrl];
   
}
#pragma mark - 微信朋友圈
- (void)shareWechatFriendsCircle{
    
    __weak typeof(self) weakSelf = self;
    NSURL *url = [NSURL URLWithString:kLogoUrl];
    NSData *imgData = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:imgData];
    NSArray* imageArray = @[image];
    
    if (imageArray) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"我正在德智微课堂学习名师课程，领大礼包学8700个初高中必考知识点!" images:imageArray url:[NSURL URLWithString:@"http://www.dezhi.com/andriodwk/share-download"] title:@"【德智微课堂】新用户下载即送会员大礼包" type:SSDKContentTypeAuto];
        [ShareSDK share:SSDKPlatformSubTypeWechatTimeline parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
            
            [weakSelf dealShreResuleWithState:state error:error];
        }];
    }
}
#pragma mark - 微信朋友
- (void)shareWechatFriends{
    __weak typeof(self) weakSelf = self;
    NSURL *url = [NSURL URLWithString:kLogoUrl];
    NSData *imgData = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:imgData];
    NSArray* imageArray = @[image];
    if (imageArray) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"我正在德智微课堂学习名师课程，领大礼包学8700个初高中必考知识点!" images:imageArray url:[NSURL URLWithString:@"http://www.dezhi.com/andriodwk/share-download"] title:@"【德智微课堂】新用户下载即送会员大礼包" type:SSDKContentTypeAuto];
        [ShareSDK share:SSDKPlatformSubTypeWechatSession parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
            
            [weakSelf dealShreResuleWithState:state error:error];
        }];
    }
}
- (void)WKShareView:(WKShareView *)shareView WithCancelAction:(UIButton *)sender{
    
    [shareView removeFromSuperview];
}
#pragma mark -意见反馈
- (void)ideaAction{
    [MobClick profileSignInWithPUID:@"usercenter_feedback"];
    
    WKIdeaViewController *ideaVC = [[WKIdeaViewController alloc]init];
   [self.navigationController pushViewController:ideaVC animated:YES];
}
#pragma mark -设置
- (void)settingsAction{
    [MobClick profileSignInWithPUID:@"usercenter_setting"];
    
    WKSettingsController *settingVC = [[WKSettingsController alloc]init];
    [self.navigationController pushViewController:settingVC animated:YES];
}

#pragma mark - 我的收藏
- (void)collectionTap:(UITapGestureRecognizer*)tap{
    [MobClick profileSignInWithPUID:@"usercenter_collection"];
    __weak typeof(self) weakSelf = self;
    WKCollectionViewController *collectionVC = [[WKCollectionViewController alloc]init];
    collectionVC.block = ^{
        [weakSelf loadCollectionData];
    };
     [self.navigationController pushViewController:collectionVC animated:YES];
    
}
#pragma mark - 我的下载
- (void)downLoadTap:(UITapGestureRecognizer*)tap{
    [MobClick profileSignInWithPUID:@"usercenter_download"];
    __weak typeof(self) weakSelf = self;
    WKDownLoadViewController *downVC = [[WKDownLoadViewController alloc]init];
    downVC.block = ^{
        [weakSelf loadDownloadData];
        weakSelf.downLoadNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)weakSelf.downLoadList.count];
    };
    [self.navigationController pushViewController:downVC animated:YES];
}
#pragma mark - 观看记录
- (void)watchTap:(UITapGestureRecognizer*)tap{
    [MobClick profileSignInWithPUID:@"usercenter_wathrecord"];
    __weak typeof(self) weakSelf = self;
    WKWatchViewController *watchVC = [[WKWatchViewController alloc]init];
    watchVC.block = ^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        [weakSelf loadWatchData];
        weakSelf.watchNumLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)weakSelf.watchList.count];
    };
    [self.navigationController pushViewController:watchVC animated:YES];
}


//处理分享结果
- (void)dealShreResuleWithState:(SSDKResponseState)state error:(NSError*)error{
    
    switch (state) {
        case SSDKResponseStateSuccess:{
            
            break;
        }
        case SSDKResponseStateFail:{
            [self showCustomAlertMessage:@"分享失败"];
            
            break;
        }
        case SSDKResponseStateCancel:{
            [self showCustomAlertMessage:@"分享取消"];
        }
        default:
            break;
    }
}
#pragma mark - date转换成毫秒
-(long long)getDateTimeTOMilliSeconds:(NSDate *)datetime{
    
    NSTimeInterval interval = [datetime timeIntervalSince1970];
    
   // NSLog(@"转换的时间戳=%f",interval);
    
    long long totalMilliseconds = interval*1000 ;
    
    //NSLog(@"totalMilliseconds=%llu",totalMilliseconds);
    
    return totalMilliseconds;
    
}

//将时间数据（毫秒）转换为天和小时
- (NSString*)getOvertime:(long long)mStr{
    
    if (mStr <= 0){
        return @"";
    }
    
    NSInteger d = mStr/1000/60/60/24;
    NSInteger h = mStr/1000/60/60%24;
    //NSInteger  m = msec/1000/60%60;
    //NSInteger  s = msec/1000%60;
    
    NSString *_tStr = @"";
    NSString *_dStr = @"";
    NSString *_hStr = @"";
    NSString *_hTimeType = @"defaultColor";
    
    if (d > 0)
    {
        _dStr = [NSString stringWithFormat:@"%ld天",(long)d];
    }
    
    if (h > 0)
    {
        _hStr = [NSString stringWithFormat:@"%ld小时",(long)h];
    }
    
    //小于2小时 高亮显示
    if (h > 0 && h < 2)
    {
        _hTimeType = @"hightColor";
    }
    
    _tStr = [NSString stringWithFormat:@"%@",_dStr];
    
    return _tStr;
}
#pragma mark - 毫秒转换时间
-(NSDate *)getDateTimeFromMilliSeconds:(long long) miliSeconds{
    
    NSTimeInterval tempMilli = miliSeconds;
    
    NSTimeInterval seconds = tempMilli/1000.0;//这里的.0一定要加上，不然除下来的数据会被截断导致时间不一致
    
   // NSLog(@"传入的时间戳=%f",seconds);
    
    return [NSDate dateWithTimeIntervalSince1970:seconds];
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat offset = scrollView.contentOffset.y + scrollView.contentInset.top;
    //放大
    if (offset <= 0){
        _headerView.y = 20;
        _headerView.height = kHeaderHeight - offset;
        _headerImageView.alpha = 1;
//        self.statusbar.alpha = 1;
    }else{//缩小
        _headerView.height = kHeaderHeight;
        CGFloat min = kHeaderHeight - 44;
        _headerView.y = -MIN(min, offset)+20;
        CGFloat progress = 1 - (offset / min);
        _headerImageView.alpha = progress;
//        self.statusbar.alpha = progress;
    }
    // 设置图像高度
    _headerImageView.height = _headerView.height;
    // 设置分隔线的位置
    _lineView.y = _headerView.height - _lineView.height;
}
- (UIView *)statusView{
    if (!_statusView) {
        _statusView = [[UIView alloc]init];
        _statusView.backgroundColor = RGBColor(40, 188, 203);
    }
    return _statusView;
}
-(UIImageView *)avaderImgView{
    
    if (_avaderImgView==nil) {
        _avaderImgView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 40, 76, 76)];
        _avaderImgView.image = IMG(@"icon_avader");
        _avaderImgView.layer.cornerRadius = 38;
        _avaderImgView.layer.masksToBounds = YES;
        _avaderImgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(avaderAntion:)];
        [_avaderImgView addGestureRecognizer:tapGestureRecognize];
    }
    return _avaderImgView;
}
- (YYLabel *)nickLabel{
    if (_nickLabel == nil) {
        _nickLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.avaderImgView.frame)+20, 40, 150, 21)];
        _nickLabel.textColor = [UIColor whiteColor];
        _nickLabel.textAlignment = NSTextAlignmentLeft;
        _nickLabel.font = [UIFont systemFontOfSize:15];
        //_nickLabel.text = @"粉红色的小鸟";
    }
    return _nickLabel;
}
-(YYLabel *)juniorLabel{
    
    if (_juniorLabel==nil) {
        _juniorLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.avaderImgView.frame)+20, 40+21+5, 60, 20)];
        _juniorLabel.textAlignment = NSTextAlignmentCenter;
        _juniorLabel.textColor = [UIColor whiteColor];
        _juniorLabel.font = [UIFont systemFontOfSize:11];
        _juniorLabel.layer.cornerRadius = 8;
        _juniorLabel.layer.masksToBounds = YES;
        _juniorLabel.hidden = YES;
        _juniorLabel.text = @"初中会员";
        _juniorLabel.backgroundColor = RGBColor(255, 197, 26);
    }
    return _juniorLabel;
}
- (YYLabel *)juniorRemainingDayLabel{
    if (_juniorRemainingDayLabel == nil) {
        _juniorRemainingDayLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.juniorLabel.frame)+8, 40+21+3, 80, 21)];
        _juniorRemainingDayLabel.hidden = YES;
        _juniorRemainingDayLabel.textColor = [UIColor whiteColor];
        _juniorRemainingDayLabel.textAlignment = NSTextAlignmentLeft;
        _juniorRemainingDayLabel.font = [UIFont systemFontOfSize:11];
       // _juniorRemainingDayLabel.text = @"剩余515天";
    }
    return _juniorRemainingDayLabel;
}
-(YYLabel *)highLabel{
    
    if (_highLabel==nil) {
        _highLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.avaderImgView.frame)+20, 40+21+5+30, 60, 20)];
        _highLabel.hidden = YES;
        _highLabel.textAlignment = NSTextAlignmentCenter;
        _highLabel.textColor = [UIColor whiteColor];
        _highLabel.font = [UIFont systemFontOfSize:11];
        _highLabel.layer.cornerRadius = 8;
        _highLabel.layer.masksToBounds = YES;
        _highLabel.text = @"高中会员";
        _highLabel.backgroundColor = RGBColor(255, 155, 25);
    }
    return _highLabel;
}
- (YYLabel *)hightRemainingDayLabel{
    if (_hightRemainingDayLabel == nil) {
        _hightRemainingDayLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.highLabel.frame)+8, 40+21+30+3, 80, 21)];
        _hightRemainingDayLabel.hidden = YES;
        _hightRemainingDayLabel.textColor = [UIColor whiteColor];
        _hightRemainingDayLabel.textAlignment = NSTextAlignmentLeft;
        _hightRemainingDayLabel.font = [UIFont systemFontOfSize:11];
        //_hightRemainingDayLabel.text = @"剩余515天";
    }
    return _hightRemainingDayLabel;
}
- (UIButton *)messageBtn{
    if (_messageBtn == nil) {
        _messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_messageBtn setImage:IMG(@"icon_message") forState:UIControlStateNormal];
        _messageBtn.frame =CGRectMake(_headerView.width-40, 5, 35, 35);
        [_messageBtn addTarget:self action:@selector(messageBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _messageBtn;
}
- (UILabel *)redLabel{
    
    if (_redLabel == nil) {
        
        _redLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.messageBtn.frame)-12, 12, 5, 5)];
        _redLabel.backgroundColor = [UIColor redColor];
        _redLabel.layer.cornerRadius = 2.5;
        _redLabel.layer.masksToBounds = YES;
        
    }
    return _redLabel;
}

- (YYLabel *)collectionNumLabel{
    if (_collectionNumLabel == nil) {
        _collectionNumLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.avaderImgView.frame)+20, (_headerView.width-2)/3, 31)];
        _collectionNumLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _collectionNumLabel.textAlignment = NSTextAlignmentCenter;
        _collectionNumLabel.font = [UIFont systemFontOfSize:25];

        _collectionNumLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(collectionTap:)];
        [_collectionNumLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _collectionNumLabel;
    
}
- (YYLabel *)collectionLabel{
    if (_collectionLabel == nil) {
        _collectionLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, _headerView.height-31, (_headerView.width-2)/3, 21)];
        _collectionLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _collectionLabel.textAlignment = NSTextAlignmentCenter;
        _collectionLabel.font = [UIFont systemFontOfSize:13];
        _collectionLabel.text = @"我的收藏";
        _collectionLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(collectionTap:)];
        [_collectionLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _collectionLabel;
    
}
- (UIView *)leftLineView{
    
    if (_leftLineView == nil) {
        _leftLineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.collectionLabel.frame), CGRectGetMaxY(self.avaderImgView.frame)+20, 1, _headerView.height-CGRectGetMaxY(self.collectionNumLabel.frame)+18)];
        _leftLineView.backgroundColor = [UIColor colorWithHexString:@"#007380"];
    }
    return _leftLineView;
}
- (YYLabel *)downLoadNumLabel{
    if (_downLoadNumLabel == nil) {
        _downLoadNumLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.leftLineView.frame), CGRectGetMaxY(self.avaderImgView.frame)+20, (_headerView.width-2)/3, 31)];
        _downLoadNumLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _downLoadNumLabel.textAlignment = NSTextAlignmentCenter;
        _downLoadNumLabel.font = [UIFont systemFontOfSize:25];
        //_downLoadNumLabel.text = @"35";
        _downLoadNumLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(downLoadTap:)];
        [_downLoadNumLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _downLoadNumLabel;
    
}
- (YYLabel *)downLoadLabel{
    if (_downLoadLabel == nil) {
        _downLoadLabel = [[YYLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.leftLineView.frame), _headerView.height-31, (_headerView.width-2)/3, 21)];
        _downLoadLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _downLoadLabel.textAlignment = NSTextAlignmentCenter;
        _downLoadLabel.font = [UIFont systemFontOfSize:13];
        _downLoadLabel.text = @"我的下载";
        _downLoadLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(downLoadTap:)];
        [_downLoadLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _downLoadLabel;
    
}
- (UIView *)rightLineView{
    
    if (_rightLineView == nil) {
        _rightLineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.downLoadNumLabel.frame), CGRectGetMaxY(self.avaderImgView.frame)+20, 1, _headerView.height-CGRectGetMaxY(self.downLoadNumLabel.frame)+21)];
        _rightLineView.backgroundColor = [UIColor colorWithHexString:@"#007380"];
    }
    return _rightLineView;
}
- (YYLabel *)watchNumLabel{
    if (_watchNumLabel == nil) {
        _watchNumLabel = [[YYLabel alloc]initWithFrame:CGRectMake(_headerView.width-((_headerView.width-2)/3), CGRectGetMaxY(self.avaderImgView.frame)+20, (_headerView.width-2)/3, 31)];
        _watchNumLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _watchNumLabel.textAlignment = NSTextAlignmentCenter;
        _watchNumLabel.font = [UIFont systemFontOfSize:25];
       // _watchNumLabel.text = @"35";
        _watchNumLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(watchTap:)];
        [_watchNumLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _watchNumLabel;
    
}
- (YYLabel *)watchLabel{
    if (_watchLabel == nil) {
        _watchLabel = [[YYLabel alloc]initWithFrame:CGRectMake(_headerView.width-((_headerView.width-2)/3), _headerView.height-31, (_headerView.width-2)/3, 21)];
        _watchLabel.textColor = [UIColor colorWithHexString:@"#007380"];
        _watchLabel.textAlignment = NSTextAlignmentCenter;
        _watchLabel.font = [UIFont systemFontOfSize:13];
        _watchLabel.text = @"观看记录";
        _watchLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(watchTap:)];
        [_watchLabel addGestureRecognizer:tapGestureRecognizer];
    }
    return _watchLabel;
    
}
- (WKShareView *)shareView{
    if (!_shareView) {
        _shareView = [[WKShareView alloc]init];
        _shareView.delegate = self;
    }
    return _shareView;
}
- (UIButton *)btnBack{
    
    if (!_btnBack) {
        _btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnBack.frame = CGRectMake(10, 5, 35, 35);
        [_btnBack setImage:IMG(@"icon_return_white") forState:UIControlStateNormal];
        [_btnBack addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnBack;
}
- (void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    self.statusView.frame = CGRectMake(0, 0, self.view.width, 20);
   
    self.shareView.frame = CGRectMake(0, 0, kDeviceScreenWidth, kDeviceScreenHeight);
}
//比较时间方法
- (NSDate *)StringTODate:(NSString *)sender{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"YYYY-MMMM-dd";
    [dateFormatter setMonthSymbols:[NSArray arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12", nil]];
//    [NSArray  arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12", nil,nil]
    NSDate * ValueDate = [dateFormatter dateFromString:sender];
    return ValueDate;
}
- (NSInteger)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    
    if (result == NSOrderedDescending) {
        //在指定时间前面 过了指定时间 过期
        return 1;
    }
    else if (result == NSOrderedAscending){
        //没过指定时间 没过期
        return -1;
    }
    //刚好时间一样.
    return 0;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
